/**
 * tigerrad
 * fall 2006
 */
#include "Camera.h"

#ifndef _LIGHT_H
#define _LIGHT_H

class Light
{
	public:
		/**
		 * Constructor.
		 * @param mat Color properties of the light
		 * @param verts Light position (assuming rectangular light)
		 * @param dir Light direction
		 * @param up up direction, used when rendering from the light
		 * @param fov GL_SPOT_DIRECTION
		 * @param spotExp GL_SPOT_EXPONENT
		 * @param att Attentuation factors (constant, linear, quadratic)
		 */
		Light(const Material& mat, Vec3 verts[4], const Vec3& dir, const Vec3& up,
			float fov, float exp, const Vec3& att = Vec3(1.0, 0.0, 0.0))
			: _mat(mat), _dir(dir), _up(up), _fov(fov), _spotExp(exp), _att(att)
		{
			_verts[0] = verts[0];
			_verts[1] = verts[1];
			_verts[2] = verts[2];
			_verts[3] = verts[3];
		}

		/**
		 * Return the diffuse color of this area light.
		 */
		Vec3 getDiffuse() const { return _mat.diffuse; }

		/**
		 * Return the light direction.
		 */
		Vec3 getDir() const { return _dir; }

		/**
		 * Return the up direction, used when rendering from this light.
		 */
		Vec3 getUp() const { return _up; }

		/**
		 * Return the center (position) of the light
		 */
		Vec3 getCenter() const
		{
			Vec3 c(0.0, 0.0, 0.0);
			c += _verts[0];
			c += _verts[1];
			c += _verts[2];
			c += _verts[3];
			return c/4;
		}

		/**
		 * Return the fov of the light.  
		 * This is equivalent to GL_SPOT_CUTOFF for OpenGL spotlights.
		 */
		float getFov() const { return _fov; }

		/** 
		 * Set the fov of the light.
		 */
		void setFov(float f) { assert(f >= 0 && f <= 90); _fov = f; }

		/**
		 * Return the spotlight exponent, GL_SPOT_EXPONENT, of the light
		 */
		float getSpotExp() const { return _spotExp; }

		/**
		 * Return the attenuation values
		 * 0 is constant
		 * 1 is linear
		 * 2 is quadratic
		 */
		 Vec3 getAtt() { return _att; }

		 /**
		  * Return the ith vertex of the light.
		  */
		 Vec3 getVert(unsigned int i) { assert(i<4); return _verts[i]; }
		
		/**
		 * Destructor.
		 */
		virtual ~Light() { }
		
	protected:
		Material _mat;
		Vec3 _verts[4];
		Vec3 _dir;
		Vec3 _up;
		float _fov;
		float _spotExp;
		Vec3 _att;
		Camera _cam;

};

typedef boost::shared_ptr<Light> LightPtr;

#endif

